layui.define(['element', 'layer', 'jquery', 'form','laydate','laypage'], function(exports) {
    var element = layui.element(),
        layer = layui.layer,
        $ = layui.jquery,
        form = layui.form(),
        laydate = layui.laydate,
        laypage = layui.laypage,
        $pageId = $("#page"),
        $pagesNum = parseInt($("#page").attr("data-page")),
        $page,
        $javaUrl = '/fun?page='; //分页接口地址

    laypage({
        cont: $pageId
        ,pages: $pagesNum
        ,skip: true
        ,first:1
        ,skin: $pagesNum > 3 ? '#1E9FFF' : '#009688'
        ,curr: function(){ //通过url获取当前页，也可以同上（pages）方式获取
            $page = location.search.match(/page=(\d+)/);
            return $page ? $page[1] : 1;
            console.log($page)
        }()
        ,jump: function(e, first){ //触发分页后的回调
            if(!first){ //一定要加此判断，否则初始时会无限刷新
                location.href = $javaUrl+e.curr;
            }
        }
    });

    /* form.on('checkbox(allChoose)', function(data){
        var child = $(data.elem).parents('table').find('tbody tr>td:first-child input[type="checkbox"]');
        child.each(function(index, item){
            item.checked = data.elem.checked;
        });
        form.render('checkbox');
    });

    //监听指定开关
    form.on('switch', function(data){
        layer.tips('温馨提示：请注意开关状态--'+ (this.checked ? '开' : '关'), data.othis)
    });

    var tablechecked='';
    var checkNum=0;
    function chd(){
        tablechecked=$('#admin_form tbody>tr>td:first-child>input:checked');
        checkNum=tablechecked.length;
    }
    form.on('checkbox', function(data){
        chd();
    });
    //全选
    form.on('checkbox(allChoose)', function(data){
        var child = $(data.elem).parents('table').find('tbody>tr>td:first-child input[type="checkbox"]');
        child.each(function(index, item){
            item.checked = data.elem.checked;
        });
        form.render('checkbox');
        chd();
    });

//        添加
    $('#add_admin').on('click', function(data){
        //iframe窗
        layer.open({
            type: 2,
            title: '添加',
            shadeClose: true,
            //shade: true,
            area: ['893px', '600px'],
            content: '//fly.layui.com/'
        });
    });
//        修改
    $('#modification').on('click', function(e){
        e.preventDefault();
        layer.msg('修改');
        if(checkNum==0){
            layer.msg('请至少选择一项修改');
        }else if(checkNum==1){
            var trId=$(tablechecked).parent().parent().attr('id');
            window.location.href="网页地址?id="+trId;
        }else if(checkNum>1){
            layer.msg('最多只能选择一项修改');
        }
    });

//        删除
    $('#delete_cont').bind('click',function(e){
        e.preventDefault();
        chd();
        var trId=[];
        if(checkNum==0){
            layer.msg('请至少选择一项删除内容');
        }else if(checkNum>=1){
            $(tablechecked).each(function(){
                $(this).parent().parent().remove();
                trId.push($(this).parent().parent().attr('id'));
            });
            trId.join(',');

            if(trId){
                layer.confirm('确认删除？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        url: url,
                        type: 'post',
                        data:{
                            id:trId
                        },
                        success:function(data){
                            if(data.result){
                                $('#search_form').submit();
                                layer.msg('删除成功');
                            }else{
                                layer.msg('无法删除');
                            }
                        }
                    });
                });
            }
        }
        chd();
    });
//        清空
    $('#admin_reset').click(function(e){
        e.preventDefault();
        $('#search_form input').each(function(){
            $(this).val('');
        });
    });*/
    exports('admin_manage', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});
